import { bindActionCreators } from 'redux';
import {getTypeImage,getCurTypeList} from '../../api/img';
import {ItypeParams,ICurTypeParams} from '../../interface/img';
import {INIT_TYPE_IMAGE,SET_CUR_TYPELIST,SET_ACTIVE_INDEX,INIT_TYPE_LIST} from '../types/img.type';

//获取分类图片数据的action

export const getTypeImageAction = (params:ItypeParams) => {
    return (dispatch:any) => {
        getTypeImage(params).then(res => {
            if(res.data.code === 1){
                dispatch({
                    type:INIT_TYPE_IMAGE,
                    list:res.data.data
                })
            }
        })
    }
}

//获取指定分类图片列表数据
export const getCurTypeAction = (params:ICurTypeParams) => {
    return (dispatch:any) => {
        getCurTypeList(params).then(res => {
            if(res.data.code ===1){
                dispatch({
                    type:SET_CUR_TYPELIST,
                    list:res.data.data.List
                })
            }
        })
    }
}

// let dispatch = useDispatch();

// getTypeImageAction()(dispatch);

// bindActionCreators

//设置activeIndex
export const setActiveIndex = (index:number) => {
    return {
        type:SET_ACTIVE_INDEX,
        index
    }
}

//初始化指定分类图片列表数据
export const initTypeList = () => {
    return {
        type:INIT_TYPE_LIST
    }
}
